<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="div1">这是一个div</div>
    <div id="div2">这里有一把大伞</div>
    <div id="div3">
        <p id="p1">这是一个p1</p>
        <span>yes</span>
    </div>
    <div id="div4"></div>
    <div id="div5">js属性操作</div>
    <div id="div6">666</div>
    <span class="myspan">这是一个span</span>
    <p >这是一个p</p>
    <ul>
        <li>语文</li>
        <li>数学</li>
        <li>英语</li>
    </ul>

    <script>
        // append追加
        let div1=document.getElementById("div1")
        console.log(div1)
        div1.innerHTML="这是一条小鱼"
        let myfish=document.createElement("div")
        myfish.innerHTML="这是我创造的一条小鱼"
        div1.append(myfish)
        div1.prepend("这是谁的小鱼")
        // querySelector选择
        let div2=document.querySelector("#div2")
        console.log(div2)
        let div3=document.querySelector(".myspan")
        console.log(div3)
        let divs=document.getElementsByTagName("div")
        console.log(divs)
        // insertBefore
        let p1=document.getElementById("p1")
        let myEle=document.createElement("h1")
        myEle.innerHTML="哈哈"
        let myEle2=document.createElement("h2")
        myEle2.innerHTML="不哈哈"
        let div6=document.getElementById("div3")
        div6.insertBefore(myEle,p1)
        p1.before(myEle2)
        p1.after(myEle2)
        // 删除元素
        let myspan=document.getElementsByClassName("myspan")
        console.log(myspan)
        myspan[0].remove();
        // 复杂方式删除
        let list=document.getElementsByTagName("ul")
        console.log(list)
        console.log(list[0].firstElementChild)
        console.log(list[0].firstElementChild.nextElementSibling)
        list[0].children[0]
        console.log(p1.parentElement)
        p1.parentElement.removeChild(p1)
        // js属性操作
        let div5=document.getElementById("div5")
        div5.title="xxx"
        div5.style.color="blue"
        div5.style.backgroundColor="green"
        div5.setAttribute("title","yyy")
        div5.getAttribute("title")
    </script>
</body>
</html>